/**
 * 期费用预提 - 批次产生页面
 * @author shixc
 * @date 2019/10/26
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        vueData = {
            form: {
                GWFC001: null,
                GWFC002: null,
                GWFC003:null
            },
            rules: {
                GWFC001: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWFC002: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ]
            },
            selectOptions:{
                GWFC002Options:app.datas_("crm_gwat550_qb")
            }
        },
        callObj
    ;

    var Gwft200Auto = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _tag: 'gwft200_auto',
                _loadTplsFull: [{
                    dom: 'common_open_window', tpl: 'common/_open_window'
                }
                ]
            }, win);
        },

        batchGeneration: function () {
            app.ajax({
                xurl: 'crm/gwft200/beforeGeneration',
                xdata: vueData.form,
                loading: true,
                cb: function (result) {
                    if (result.ok) {
                        if(result.data.data.COUNT1 == 0){//已审核==0
                            if(result.data.data.COUNT2 > 0){//未审核 > 0
                                app.confirm({
                                    msg: '该' + vueData.form.GWFC001 + '年度' + vueData.form.GWFC002 + '月份已经有数据了，是否覆盖？',
                                    ok: function (e) {
                                        self.autoGeneration();
                                    }
                                });
                            }else {
                                self.autoGeneration();
                            }
                        }else {
                            self._closeTpl();
                            app.showMessage('该'+ vueData.form.GWFC001+ '年度'+ vueData.form.GWFC002 + '月份已有确认数据!');
                            return;
                        }
                    }
                }
            });
        },

        autoGeneration: function () {
            app.ajax({
                xurl: 'crm/gwft200/batchGeneration',
                xdata: vueData.form,
                loading: true,
                okmsg: '批量生成成功',
                cb: function (result) {
                    if (result.ok) {
                        app.pageModule('gwft200').reloadTableCurr();
                        self._closeTpl();
                        app.showMessage(result.data.data.message);
                    }
                }
            });
        },

        _call: function (tagData) {
            vueData.form.GWFC001 = '';
            vueData.form.GWFC002 = '';
            vueData.form.GWFC003 = '';
        },
        _ready: function () {
            var vue = new Vue({
                el: '#gwft200_auto',
                data: vueData,
                methods: {
                    cancel: function () {
                        self._closeTpl();
                    },
                    sure: function () {
                        this.$refs['form'].validate(function (valid) {
                            if (valid) {
                                self.batchGeneration();
                            }
                        });
                    },
                    openGwad:function () {
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                multiple: true,
                                config: {
                                    method: 'q_gwad002',
                                    columnList: [
                                        {label: '区域编号', prop: 'GWAD002', width: '150'},
                                        {label: '区域名称', prop: 'GWADL004', width: '150'},
                                        {label: '助记码', prop: 'GWADL005', width: '150'}
                                    ],
                                    dataList: []
                                },
                                cb: function (data) {
                                    for(var i = 0; i < data.length; i ++) {
                                        if(i == 0) {
                                            vueData.form.GWFC003 = vueData.form.GWFC003 + data[i].GWAD002;
                                        }else{
                                            vueData.form.GWFC003 = vueData.form.GWFC003 + ',' + data[i].GWAD002;
                                        }
                                    }
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择区域',
                                area: ['600px', '465px']
                            }
                        });
                    }
                },
                watch: {},
                created: function () {
                    self._setEleIsReady('gwft200_auto');
                }
            });
        },

        _lazy: function () {
            this._super();
        }
    });

    return new Gwft200Auto();

});